package Shangji2.calculator;

import Shangji2.calculator.factory.*;

import java.util.Scanner;

public class CalculatorTest {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入第一个数字：");
        double num1 = scanner.nextDouble();
        System.out.print("请输入运算符（+、-、*、/、%）：");
        String operator = scanner.next();
        System.out.print("请输入第二个数字：");
        double num2 = scanner.nextDouble();

        // 根据操作符选择对应的工厂
        CalculatorFactory factory;
        switch (operator) {
            case "+":
                factory = new AddFactory();
                break;
            case "-":
                factory = new SubtractFactory();
                break;
            case "*":
                factory = new MultiplyFactory();
                break;
            case "/":
                factory = new DivideFactory();
                break;
            case "%":
                factory = new ModFactory();
                break;
            default:
                throw new IllegalArgumentException("不支持的操作符：" + operator);
        }

        // 通过工厂创建运算实例并执行计算
        Calculator calculator = factory.createCalculator();
        double result = calculator.calculate(num1, num2);
        System.out.println("计算结果：" + num1 + operator + num2 + "=" + result);

        scanner.close();
    }
}